home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / forth / amiga / amigaker.arc / 04.vars < prev    next >
Text File  |  1987-12-30  |  19KB  |  555 lines

  1. ;
  2. ;  04.vars&strings
  3. ;
  4. ;  System variables
  5. ;
  6. ;  String handling
  7. ;
  8.  
  9. * sp0             Initial stack pointer, a variable.
  10.                   ; Set by initializing code, used to reset system
  11.                   dc.w     -1
  12.                   dc.l     link3
  13. link3             set      *-4
  14.                   dc.b     $83,'sp',$80!'0'
  15.                   cnop     0,2
  16. _sp0              dc.l     docreate
  17. init_sp           dc.l     0
  18.  
  19. * rp0             Initial return pointer, a variable.
  20.                   ; Set by initializing code, used to reset the system.
  21.                   dc.w     -1
  22.                   dc.l     link2
  23. link2             set      *-4
  24.                   dc.b     $83,'rp',$80!'0'
  25.                   cnop     0,2
  26. _rp0              dc.l     docreate
  27. init_rp           dc.l     0
  28.  
  29. * dp              Dictionairy Pointer, a variable.
  30. ; Holds place where compilation takes place. Set to stdbuffer until the
  31. ; start routine is executed, then the user dictionary is allocated and dp
  32. ; is set to the start of user dictionary.
  33.                   dc.w     -1
  34.                   dc.l     link0
  35. link0             set      *-4
  36.                   dc.b     $82,'d',$80!'p'
  37.                   cnop     0,2
  38. _dp               dc.l     docreate
  39.                   dc.l     stdbuffer
  40.  
  41. ; the next two cells hold the start of the userdictionary and the length
  42. ; these are patched by the startup routine, after the memory block is
  43. ; allocated.
  44.                   dc.l     0
  45.                   dc.l     $10000
  46.  
  47. * #out            Number characters output since last cr.
  48.                   dc.w     -1
  49.                   dc.l     link3
  50. link3             set      *-4
  51.                   dc.b     $84,'#ou',$80!'t'
  52.                   cnop     0,2
  53. _number_out       dc.l     docreate,0
  54.  
  55. * #line           Number of cr since last 'page'
  56.                   dc.w     -1
  57.                   dc.l     link3
  58. link3             set      *-4
  59.                   dc.b     $85,'#lin',$80!'e'
  60.                   cnop     0,2
  61. _number_line      dc.l     docreate,0
  62.  
  63. * base            Base holds the current number radix.
  64.                   dc.w     -1
  65.                   dc.l     link2
  66. link2             set      *-4
  67.                   dc.b     $84,'bas',$80!'e'
  68.                   cnop     0,2
  69. _base             dc.l     docreate,10
  70.  
  71. * hld             Hold is used in number conversions for output.
  72.                   dc.w     -1
  73.                   dc.l     link0
  74. link0             set      *-4
  75.                   dc.b     $83,'hl',$80!'d'
  76.                   cnop     0,2
  77. _hld              dc.l     docreate,0
  78.  
  79. * 'file           pointer to current file info block.
  80.                   dc.w     -1
  81.                   dc.l     link0
  82. link0             set      *-4
  83.                   dc.b     $85,$2C,'fil',$80!'e'
  84.                   cnop     0,2
  85. _tick_file        dc.l     docreate,0
  86.  
  87. * 'in-file        pointer to current file info block for input
  88.                   dc.w     -1
  89.                   dc.l     link0
  90. link0             set      *-4
  91.                   dc.b     $88,$2C,'in-fil',$80!'e'
  92.                   cnop     0,2
  93. _tick_in_file     dc.l     docreate,0
  94.  
  95. * type            Deferred routine. Normally  (type).
  96. ; Could be set to 2drop to discard output. (e.g.)
  97.                   dc.w     -1
  98.                   dc.l     link0
  99. link0             set      *-4
  100.                   dc.b     $84,'typ',$80!'e'
  101.                   cnop     0,2
  102. _type             dc.l     dodefer,_nest_type
  103.  
  104. * key             Deferred routine. Normally set to  (key)
  105. ; allows input from eg. diskfile, see getc in dos.
  106.                   dc.w     -1
  107.                   dc.l     link3
  108. link3             set      *-4
  109.                   dc.b     $83,'ke',$80!'y'
  110.                   cnop     0,2
  111. _key              dc.l     dodefer,_nest_key
  112.  
  113. * key?            Deferred routine. Normally set to  (key?)
  114. ; This ones tricky. If key is set to getc then this could return true
  115. ; until eof is reached. Routine key doesn't call key?.
  116.                   dc.w     -1
  117.                   dc.l     link3
  118. link3             set      *-4
  119.                   dc.b     $84,'key',$80!'?'
  120.                   cnop     0,2
  121. _key_question     dc.l     dodefer,_nest_key_question
  122.  
  123. * prior           points to last dictionairy searched.
  124.                   dc.w     -1
  125.                   dc.l     link0
  126. link0             set      *-4
  127.                   dc.b     $85,'prio',$80!'r'
  128.                   cnop     0,2
  129. _prior            dc.l     docreate,0
  130.  
  131. * state           Compiling or Interpreting
  132.                   dc.w     -1
  133.                   dc.l     link3
  134. link3             set      *-4
  135.                   dc.b     $85,'stat',$80!'e'
  136.                   cnop     0,2
  137. _state            dc.l     docreate,0
  138.  
  139. * warning         Flag, if on gives warning if duplicate word
  140.                   dc.w     -1
  141.                   dc.l     link3
  142. link3             set      *-4
  143.                   dc.b     $87,'warnin',$80!'g'
  144.                   cnop     0,2
  145. _warning          dc.l     docreate,-1
  146.  
  147. * dpl             decimal point location for numeric input.
  148.                   dc.w     -1
  149.                   dc.l     link0
  150. link0             set      *-4
  151.                   dc.b     $83,'dp',$80!'l'
  152.                   cnop     0,2
  153. _dpl              dc.l     docreate,0
  154.  
  155. * last            points to nfa of latest definition
  156.                   dc.w     -1
  157.                   dc.l     link0
  158. link0             set      *-4
  159.                   dc.b     $84,'las',$80!'t'
  160.                   cnop     0,2
  161. _last             dc.l     docreate,0
  162.  
  163. * csp             Stack position for error checking.
  164.                   dc.w     -1
  165.                   dc.l     link3
  166. link3             set      *-4
  167.                   dc.b     $83,'cs',$80!'p'
  168.                   cnop     0,2
  169. _csp              dc.l     docreate,0
  170.  
  171. * current         Vocabulary which receives definitions
  172.                   dc.w     -1
  173.                   dc.l     link3
  174. link3             set      *-4
  175.                   dc.b     $87,'curren',$80!'t'
  176.                   cnop     0,2
  177. _current          dc.l     docreate,_forth+4
  178.  
  179. * #vocs           Number of vocabularies to search
  180.                   dc.w     -1
  181.                   dc.l     link3
  182. link3             set      *-4
  183.                   dc.b     $85,'#voc',$80!'s'
  184.                   cnop     0,2
  185. _number_vocs      dc.l     doconstant,12
  186.  
  187. * context         The vocabulary search array
  188.                   dc.w     -1
  189.                   dc.l     link3
  190. link3             set      *-4
  191.                   dc.b     $87,'contex',$80!'t'
  192.                   cnop     0,2
  193. _context          dc.l     docreate,_forth+4,_forth+4,_root+4
  194.                   dc.l     0,0,0,0,0,0,0,0,0,0
  195.  
  196. * 'tib            Address of terminal input buffer, set when running quit
  197.                   dc.w     -1
  198.                   dc.l     link0
  199. link0             set      *-4
  200.                   dc.b     $84,$2c,'ti',$80!'b'
  201.                   cnop     0,2
  202. _tick_tib         dc.l     docreate,tibbuffer
  203.  
  204. * width           Width of the name field
  205.                   dc.w     -1
  206.                   dc.l     link3
  207. link3             set      *-4
  208.                   dc.b     $85,'widt',$80!'h'
  209.                   cnop     0,2
  210. _width            dc.l     docreate,31
  211.  
  212. * voc-link        Start of the vocabulary linked-list, in temporal order,
  213. ; used in forgetting in the proper order.
  214.                   dc.w     -1
  215.                   dc.l     link2
  216. link2             set      *-4
  217.                   dc.b     $88,'voc-lin',$80!'k'
  218.                   cnop     0,2
  219. _voc_link         dc.l     docreate,Voc_link
  220.  
  221. * lib-link        Start of linked list of Amiga libraries, which are
  222. ; mayby open or closed. A seperate word traverses the list when bye'ing
  223. ; and closes any opened library. (close-libs).
  224.                   dc.w     -1
  225.                   dc.l     link0
  226. link0             set      *-4
  227.                   dc.b     $88,'lib-lin',$80!'k'
  228.                   cnop     0,2
  229. _lib_link         dc.l     docreate,Lib_link
  230.  
  231. * file-link       Start of linked list of all the files. Will be closed
  232. ; by exiting. (close-files)
  233.                   dc.w     -1
  234.                   dc.l     link2
  235. link2             set      *-4
  236.                   dc.b     $89,'file-lin',$80!'k'
  237.                   cnop     0,2
  238. _file_link        dc.l     docreate,File_link
  239.  
  240. * >in             Offset into input stream
  241.                   dc.w     -1
  242.                   dc.l     link2
  243. link2             set      *-4
  244.                   dc.b     $83,'>i',$80!'n'
  245.                   cnop     0,2
  246. _to_in            dc.l     docreate,0
  247.  
  248. * span            Number of characters expected
  249.                   dc.w     -1
  250.                   dc.l     link3
  251. link3             set      *-4
  252.                   dc.b     $84,'spa',$80!'n'
  253.                   cnop     0,2
  254. _span             dc.l     docreate,0
  255.  
  256. * #tib            Number of characters to interpret, see word
  257.                   dc.w     -1
  258.                   dc.l     link3
  259. link3             set      *-4
  260.                   dc.b     $84,'#ti',$80!'b'
  261.                   cnop     0,2
  262. _number_tib       dc.l     docreate,0
  263.  
  264. * end?            Flag, on if input stream is exhausted.
  265.                   dc.w     -1
  266.                   dc.l     link1
  267. link1             set      *-4
  268.                   dc.b     $84,'end',$80!'?'
  269.                   cnop     0,2
  270. _end_question     dc.l     docreate,0
  271.  
  272. * loading         Variable used to indicate when a file is being loaded.
  273. ; This variable is 0 if not loading, 1 if the first level file is being
  274. ; loaded, 2 if the second etc. The number indicates the level of nesting.
  275.                   dc.w     -1
  276.                   dc.l     link0
  277. link0             set      *-4
  278.                   dc.b     $87,'loadin',$80!'g'
  279.                   cnop     0,2
  280. _loading          dc.l     docreate,0
  281.  
  282. * lb              Pointer to loadbuffer, each load file uses a seperate
  283. ; loadbuffer to keep track of loading and allow nested loading. Loadbuffers
  284. ; are 256 bytes long and have the count in the first byte.
  285.                   dc.w     -1
  286.                   dc.l     link0
  287. link0             set      *-4
  288.                   dc.b     $82,'l',$80!'b'
  289.                   cnop     0,2
  290. _lb               dc.l     docreate,0
  291.  
  292. * bl              Constant blank
  293.                   dc.w     -1
  294.                   dc.l     link2
  295. link2             set      *-4
  296.                   dc.b     $82,'b',$80!'l'
  297.                   cnop     0,2
  298. _bl               dc.l     doconstant,32
  299.  
  300. * bs              Constant backspace
  301.                   dc.w     -1
  302.                   dc.l     link2
  303. link2             set      *-4
  304.                   dc.b     $82,'b',$80!'s'
  305.                   cnop     0,2
  306. _bs               dc.l     doconstant,8
  307.  
  308. * bell            Constant bell, flashes workbench
  309.                   dc.w     -1
  310.                   dc.l     link2
  311. link2             set      *-4
  312.                   dc.b     $84,'bel',$80!'l'
  313.                   cnop     0,2
  314. _bell             dc.l     doconstant,7
  315.  
  316. * caps            A flag, if true converts to uppercase
  317.                   ; if false exact case has to be found, the default
  318.                   ; for this system. All the Amiga calls have first
  319.                   ; characters upper case as in the RKM.
  320.                   dc.w     -1
  321.                   dc.l     link3
  322. link3             set      *-4
  323.                   dc.b     $84,'cap',$80!'s'
  324.                   cnop     0,2
  325. _caps             dc.l     docreate,0
  326.  
  327. * CAPS            If caps is set on this will get it back by 0 CAPS !
  328.                   dc.w     -1
  329.                   dc.l     link3
  330. link3             set      *-4
  331.                   dc.b     $84,'CAP',$80!'S'
  332.                   cnop     0,2
  333. _CAPS             dc.l     nest,_caps,_exit
  334.  
  335. * fill            (s start-addr count char -- ) fill memory with char
  336.                   ; limited to 64k bytes
  337.                   dc.w     -1
  338.                   dc.l     link2
  339. link2             set      *-4
  340.                   dc.b     $84,'fil',$80!'l'
  341.                   cnop     0,2
  342. _fill             dc.l     *+4
  343.                   movem.l  (sp)+,d0-d1/a0
  344.                   bra.s    2$
  345. 1$                move.b   d0,(a0)+
  346. 2$                dbra     d1,1$
  347.                   jmp      (a3)
  348.  
  349. * erase           (s addr len -- )  fill string with zeroes
  350.                   dc.w     -1
  351.                   dc.l     link1
  352. link1             set      *-4
  353.                   dc.b     $85,'eras',$80!'e'
  354.                   cnop     0,2
  355. _erase            dc.l     *+4
  356.                   pea      0
  357.                   bra      _fill+4
  358.  
  359. * blank           (s addr len -- ) fill string with blanks
  360.                   dc.w     -1
  361.                   dc.l     link2
  362. link2             set      *-4
  363.                   dc.b     $85,'blan',$80!'k'
  364.                   cnop     0,2
  365. _blank            dc.l     *+4
  366.                   pea      $20
  367.                   bra      _fill+4
  368.  
  369. * count           (s addr -- addr+1 len ) returns length of the string
  370.                   ; and the string. Strings as in basic with preceding
  371.                   ; length byte.
  372.                   dc.w     -1
  373.                   dc.l     link3
  374. link3             set      *-4
  375.                   dc.b     $85,'coun',$80!'t'
  376.                   cnop     0,2
  377. _count            dc.l     *+4
  378.                   moveq    #0,d0
  379.                   move.l   (sp),a0
  380.                   move.b   (a0)+,d0
  381.                   move.l   a0,(sp)
  382.                   move.l   d0,-(sp)
  383.                   jmp      (a3)
  384.  
  385. * length          (s addr -- addr+2 len )  Same as above, for size in a word
  386.                   dc.w     -1
  387.                   dc.l     link0
  388. link0             set      *-4
  389.                   dc.b     $86,'lengt',$80!'h'
  390.                   cnop     0,2
  391. _length           dc.l     *+4
  392.                   move.l   (sp),a0
  393.                   moveq    #0,d0
  394.                   move.w   (a0)+,d0
  395.                   move.l   a0,(sp)
  396.                   move.l   d0,-(sp)
  397.                   jmp      (a3)
  398.  
  399. * move            (s from to len -- ) move strings without overlap
  400.                   dc.w     -1
  401.                   dc.l     link1
  402. link1             set      *-4
  403.                   dc.b     $84,'mov',$80!'e'
  404.                   cnop     0,2
  405. _move             dc.l     *+4
  406.                   move.l   4(sp),d0
  407.                   cmp.l    8(sp),d0
  408.                   bhi      _cmove_up+4
  409.                   bra      _cmove+4
  410.  
  411.                   ; subroutine to convert character in d4 to upper case
  412. to_upper          cmpi.b   #'a',d4           ;label - to_upper
  413.                   bcs.s    1$
  414.                   cmpi.b   #'z',d4
  415.                   bhi.s    1$
  416.                   subi.b   #32,d4
  417. 1$                rts
  418.  
  419. * upc             (s char -- char' ) change character to upper case
  420.                   dc.w     -1
  421.                   dc.l     link1
  422. link1             set      *-4
  423.                   dc.b     $83,'up',$80!'c'
  424.                   cnop     0,2
  425. _upc              dc.l     *+4
  426.                   move.w   (sp),d4
  427.                   bsr      to_upper
  428.                   move.w   d4,(sp)
  429.                   jmp      (a3)
  430.  
  431. * upper           (s addr len -- )  convert string to upper case
  432.                   dc.w     -1
  433.                   dc.l     link1
  434. link1             set      *-4
  435.                   dc.b     $85,'uppe',$80!'r'
  436.                   cnop     0,2
  437. _upper            dc.l     *+4
  438.                   move.l   (sp)+,d0
  439.                   move.l   (sp)+,a0
  440.                   bra.s    2$
  441. 1$                move.b   (a0),d4
  442.                   bsr      to_upper
  443.                   move.b   d4,(a0)+
  444. 2$                dbra     d0,1$
  445.                   jmp      (a3)
  446.  
  447. * here            (s -- addr )  return address of the next location
  448.                   dc.w     -1
  449.                   dc.l     link0
  450. link0             set      *-4
  451.                   dc.b     $84,'her',$80!'e'
  452.                   cnop     0,2
  453. _here             dc.l     *+4
  454.                   move.l   _dp+4,-(sp)
  455.                   jmp      (a3)
  456.  
  457. * pad             (s -- addr ) temporary storage for number conversion
  458.                   dc.w     -1
  459.                   dc.l     link0
  460. link0             set      *-4
  461.                   dc.b     $83,'pa',$80!'d'
  462.                   cnop     0,2
  463. _pad              dc.l     *+4
  464.                   move.l   _dp+4,-(sp)
  465.                   move.l   #160,d0           ;$a0=160
  466.                   add.l    d0,(sp)
  467.                   jmp      (a3)
  468.  
  469. * -trailing       (s addr len -- addr len' ) remove trailing blanks
  470.                   ; Strings in this system have a trailing zero to
  471.                   ; allow these strings to be used as parameters for
  472.                   ; rom calls.
  473.                   dc.w     -1
  474.                   dc.l     link1
  475. link1             set      *-4
  476.                   dc.b     $89,$2d,'trailin',$80!'g'
  477.                   cnop     0,2
  478. _minus_trailing   dc.l     *+4
  479.                   move.l   (sp)+,d0
  480.                   beq.s    4$                ;if zero return now
  481.                   move.l   (sp),a0
  482.                   tst.b    -1(a0,d0.w)       ;check last char
  483.                   bne.s    1$
  484.                   subq.l   #1,d0             ;adjust for trailing zero's
  485. 1$                add.l    d0,a0
  486.                   moveq    #32,d1
  487.                   ori      #%00100,ccr
  488.                   bra.s    3$
  489. 2$                cmp.b    -(a0),d1
  490. 3$                dbne     d0,2$
  491.                   addq.w   #1,d0
  492. 4$                move.l   d0,-(sp)
  493.                   jmp      (a3)
  494.  
  495. * comp            (s addr1 addr2 len -- -1|0|1 ) compares strings
  496.                   ; returns  -1 if str1<str2, 0 if str1=str2
  497.                   ;           1 if str1>str2.
  498.                   dc.w     -1
  499.                   dc.l     link3
  500. link3             set      *-4
  501.                   dc.b     $84,'com',$80!'p'
  502.                   cnop     0,2
  503. _comp             dc.l     *+4
  504.                   movem.l  (sp)+,d0/a0-a1
  505.                   pea      -1
  506.                   ori      #%00100,ccr       ;set z, pretend equal
  507.                   bra.s    4$
  508. 1$                cmpm.b   (a0)+,(a1)+
  509. 4$                dbne     d0,1$
  510.                   bcs.s    3$
  511.                   beq.s    2$
  512.                   addq.l   #1,(sp)
  513. 2$                addq.l   #1,(sp)
  514. 3$                jmp      (a3)
  515.  
  516. * caps-comp       same as above but each character is converted to
  517.                   ; upper case before comparing
  518.                   dc.w     -1
  519.                   dc.l     link3
  520. link3             set      *-4
  521.                   dc.b     $89,'caps-com',$80!'p'
  522.                   cnop     0,2
  523. _caps_comp        dc.l     *+4
  524.                   movem.l  (sp)+,d0/a0-a1
  525.                   pea      -1
  526.                   ori      #%00100,ccr
  527.                   bra.s    4$
  528. 1$                move.b   (a0)+,d4
  529.                   bsr      to_upper
  530.                   move.b   d4,d1
  531.                   move.b   (a1)+,d4
  532.                   bsr      to_upper
  533.                   cmp.b    d1,d4
  534. 4$                dbne     d0,1$
  535.                   bcs.s    3$
  536.                   beq.s    2$
  537.                   addq.l   #1,(sp)
  538. 2$                addq.l   #1,(sp)
  539. 3$                jmp      (a3)
  540.  
  541. * compare         do a compare depending on the caps flag, returns the
  542.                   ; same as above.
  543.                   dc.w     -1
  544.                   dc.l     link3
  545. link3             set      *-4
  546.                   dc.b     $87,'compar',$80!'e'
  547.                   cnop     0,2
  548. _compare          dc.l     *+4
  549.                   move.l   _caps+4,d0        ;tst doesn't do n(PC) as mode
  550.                                              ; this is the same
  551.                   beq      _comp+4
  552.                   bra      _caps_comp+4
  553.  
  554.  
  555.